
<template>
    <div class="col-md-9" style="padding-left: 0;width: 200px;">
      <div class="recommend-select">
        <common-select
            v-if="list.length"
            key-field="recommenderUuid"
            show-field="userName"
            val-field="recommenderUuid"
            :list="list"
            v-model="val"
            @change="change"/>
        <p v-else style="line-height: 40px;">无可选推荐人</p>
      </div>
    </div>
</template>

<script>
  import CommonSelect from '../../common/CommonSelect.vue'
  import { Service } from '../../../js/base'
  export default {
    name: "RecommendSelect",
    components: {
      CommonSelect
    },
    props: {
      value: {
        type: String,
        default: ''
      },
      /**
       * 楼盘id
       */
      premisesId: {
        type: String,
        default: ''
      },
    },
    data() {
      return {
        id: this.premisesId,
        val: this.value,
        list:  [],
      }
    },
    mounted() {
      this.getRecommendList()
    },
    methods: {
      change () {
        //this.$emit("input", this.val)
        //this.$emit("change", this.val)
      },
      getRecommendList(id = this.id) {
        const _this = this
        if(!id) {
          this.list = []
          return
        }
        const activate = '1' //1 启用， 0禁用
        Service.Recommend.getRecommendList(id, this).then(list => {
          _this.list = list.filter(item => item.status === activate)
        })
      },
    },
    watch: {
      premisesId (val) {
        this.getRecommendList(val)
      },
      val (val) {
        this.$emit("input", val)
      }
    }
  }
</script>


<style type="text/css">
  .recommend-select {
    padding-top: 5px;
  }
  .recommend-select .ivu-select-arrow { /* 不能用less scss覆盖iview样式 */
    margin-top: 0
  }
</style>
